{% extends "base.html" %}

{% block title %}鲍鱼信息查询{% endblock %}

{% block content %}
<div class="container">
    <div class="row">
        <div class="col-md-12">
            <h2 class="text-primary mb-4">鲍鱼信息查询</h2>
            
            <!-- 查询表单 -->
            <div class="card mb-4">
                <div class="card-header bg-light">
                    <h5 class="mb-0">查询条件</h5>
                </div>
                <div class="card-body">
                    <form method="POST" action="{{ url_for('search.search') }}">
                        <div class="row">
                            <div class="col-md-6">
                                <div class="input-group">
                                    <span class="input-group-text">鲍鱼编号</span>
                                    <input type="number" 
                                           class="form-control" 
                                           name="abalone_id" 
                                           placeholder="请输入鲍鱼编号"
                                           min="1"
                                           value="{{ abalone_id if abalone_id else '' }}">
                                    <button class="btn btn-warning" type="submit">查询</button>
                                </div>
                            </div>
                        </div>
                    </form>
                </div>
            </div>

            <!-- 查询结果 -->
            {% if abalone_info %}
            <div class="card">
                <div class="card-header bg-success text-white">
                    <h5 class="mb-0">鲍鱼 {{ abalone_info.id }} 号信息</h5>
                </div>
                <div class="card-body">
                    <div class="row">
                        <!-- 左侧图片区域 -->
                        <div class="col-md-4 text-center">
                            <img src="{{ url_for('static', filename='images/abalone.jpg') }}"
                                 alt="鲍鱼图片"
                                 class="img-fluid rounded mb-3"
                                 style="max-height: 300px;">
                            <div class="alert alert-info">
                                <h4>实际年龄：{{ abalone_info.rings }}岁</h4>
                            </div>
                        </div>

                        <!-- 右侧信息区域 -->
                        <div class="col-md-8">
                            <div class="table-responsive">
                                <table class="table table-bordered table-hover">
                                    <thead class="table-light">
                                        <tr>
                                            <th>属性</th>
                                            <th>值</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <tr>
                                            <td>性别</td>
                                            <td>
                                                <span class="badge bg-primary">
                                                    {{ abalone_info.sex_display }}
                                                </span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>长度(mm)</td>
                                            <td>{{ abalone_info.length }}</td>
                                        </tr>
                                        <tr>
                                            <td>直径(mm)</td>
                                            <td>{{ abalone_info.diameter }}</td>
                                        </tr>
                                        <tr>
                                            <td>高度(mm)</td>
                                            <td>{{ abalone_info.height }}</td>
                                        </tr>
                                        <tr>
                                            <td>整体重量(g)</td>
                                            <td>{{ abalone_info.whole_weight }}</td>
                                        </tr>
                                        <tr>
                                            <td>去壳重量(g)</td>
                                            <td>{{ abalone_info.shucked_weight }}</td>
                                        </tr>
                                        <tr>
                                            <td>内脏重量(g)</td>
                                            <td>{{ abalone_info.viscera_weight }}</td>
                                        </tr>
                                        <tr>
                                            <td>壳重量(g)</td>
                                            <td>{{ abalone_info.shell_weight }}</td>
                                        </tr>
                                    </tbody>
                                </table>
                            </div>

                            <!-- 预测年龄区域 -->
                            <div class="mt-4">
                                <h4 class="mb-3">预测年龄：</h4>
                                <div class="row">
                                    <div class="col-md-4">
                                        <div class="alert alert-primary">
                                            <h5 class="alert-heading">线性回归</h5>
                                            <p class="display-6">
                                                {% if abalone_info.predictions.LR %}
                                                    {{ abalone_info.predictions.LR }}岁
                                                    <small class="d-block text-muted">
                                                        {{ abalone_info.prediction_times.LR.strftime('%Y-%m-%d %H:%M') if abalone_info.prediction_times.LR else '' }}
                                                    </small>
                                                {% else %}
                                                    <span class="text-muted">暂无预测数据</span>
                                                {% endif %}
                                            </p>
                                        </div>
                                    </div>
                                    <div class="col-md-4">
                                        <div class="alert alert-info">
                                            <h5 class="alert-heading">决策树回归</h5>
                                            <p class="display-6">
                                                {% if abalone_info.predictions['DT-R'] %}
                                                    {{ abalone_info.predictions['DT-R'] }}岁
                                                    <small class="d-block text-muted">
                                                        {{ abalone_info.prediction_times['DT-R'].strftime('%Y-%m-%d %H:%M') if abalone_info.prediction_times['DT-R'] else '' }}
                                                    </small>
                                                {% else %}
                                                    <span class="text-muted">暂无预测数据</span>
                                                {% endif %}
                                            </p>
                                        </div>
                                    </div>
                                    <div class="col-md-4">
                                        <div class="alert alert-warning">
                                            <h5 class="alert-heading">随机森林回归</h5>
                                            <p class="display-6">
                                                {% if abalone_info.predictions['RF-R'] %}
                                                    {{ abalone_info.predictions['RF-R'] }}岁
                                                    <small class="d-block text-muted">
                                                        {{ abalone_info.prediction_times['RF-R'].strftime('%Y-%m-%d %H:%M') if abalone_info.prediction_times['RF-R'] else '' }}
                                                    </small>
                                                {% else %}
                                                    <span class="text-muted">暂无预测数据</span>
                                                {% endif %}
                                            </p>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            {% endif %}
        </div>
    </div>
</div>
{% endblock %}